#include "stdafx.h"
#include "MyDef.h"
#include "CSprite.h"
#include "CTexture.h"
#include "CMenu.h"
#include "CMain.h"
#include "CScene.h"
#include "CSceneTitle.h"
#include "CSceneGame.h"
#include "CSceneEnd.h"

void CSceneMgr::Init()
{
	Scene[SCENE_TITLE] = new CSceneTitle();
	Scene[SCENE_GAME]  = new CSceneGame();
	Scene[SCENE_END]   = new CSceneEnd();
	ActiveScene = Scene[SCENE_TITLE];
	ActiveScene->Init();
}

void CSceneMgr::Run()
{
	SceneType NextScene = ActiveScene->Run();
	/*if( ActiveScene != Scene[NextScene])
	{
		ChangeScene(NextScene);
	}*/
}

void CSceneMgr::End()
{
	if(ActiveScene != NULL)
	{
		ActiveScene->End();
	}

	for(int i = 0; i<SCENE_MAX; i++)
	{
		SAFE_DELETE(Scene[i]);
	}
}

void CSceneMgr::ChangeScene(int _nextScene)
{
	ActiveScene->End();
	ActiveScene = Scene[_nextScene];
	ActiveScene->Init();
}

void CSceneMgr::GotoScene(SceneType _NextScene)
{
	if( _NextScene == SCENE_MAX )
	{
		return;
	}

	if( ActiveScene != Scene[_NextScene] )
	{
		ActiveScene->End();
		ActiveScene = Scene[_NextScene];
		ActiveScene->Init();
	}
}